import 'dart:io';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/manager/xindong_yinsi_singleton.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/widgets/common/xindong_button.dart';
import 'package:xindong/widgets/dialog/xindong_base_alert.dart';

// 隐私协议
class XinDongPrivacyDialog extends StatelessWidget {
  const XinDongPrivacyDialog({super.key});

  static Future<bool> show() async {
    return await showAlertDialog(
      alert: const XinDongPrivacyDialog(),
      barrierColor: DZColors.maskColor,
      barrierDismissible: false,
    );
  }

  @override
  Widget build(BuildContext context) {
    return XinDongBaseDialog(
      hideWhenTouchOutside: false,
      body: Container(
        width: double.infinity,
        padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
        margin: const EdgeInsets.only(left: 20, right: 20),
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), color: DZColors.dialog),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const Text(
              "APP协议",
              style: TextStyle(color: DZColors.titleColor, fontSize: 18, fontWeight: FontWeight.w500),
            ),
            const SizedBox(height: 10),
            // 分割线
            Container(height: 1, color: DZColors.dividerColor),
            Container(
              constraints: const BoxConstraints(maxHeight: 260),
              child: ListView(
                padding: const EdgeInsets.only(top: 15.0, bottom: 15.0),
                children: const [
                  Text(
                    "\t\t\t\t\t\t\t在您使用我的各项服务之前，请务必审慎阅读、充分理解《 用户协议》、《 隐私政策》的条款。\n\t\t\t\t\t\t\t并且我们会申请获取您的设备信息，以向您提供安全风控服务。同时您应特别注意前述协议中免除或者限制我们责任的条款、对您权利进行限制的条款。如您已详细阅读并同意用户协议、隐私政策，请点击[ 同意并继续 ] 开始使用我们的服务。\n"
                    "\t\t\t\t\t\t\t收集个人信息为我们向您提供服务所必须哦。我们仅会将您的个人信息用于为您提供服务，若不同意此协议，我们将无法为您提供服务并退出应用。",
                    textAlign: TextAlign.start,
                    style:
                        TextStyle(fontSize: 15, fontWeight: FontWeight.normal, color: DZColors.titleColor, height: 1.5),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 5),
            const Text(
              "请您在使用产品前仔细阅读并同意",
              style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal, color: DZColors.contentColor, height: 1.5),
            ),
            const SizedBox(height: 5),
            Text.rich(
              TextSpan(
                  text: "《隐私政策》",
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      XinDongPageSingleton.instance.jumpToWebYeMian(title: "隐私政策", url: XinDongNetworking.instance.privacyUrl);
                    },
                  children: [
                    const TextSpan(text: "和", style: TextStyle(fontSize: 15, color: DZColors.titleColor)),
                    TextSpan(
                      text: "《用户协议》",
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          XinDongPageSingleton.instance.jumpToWebYeMian(title: "用户协议", url: XinDongNetworking.instance.agreementUrl);
                        },
                    ),
                  ]),
              textAlign: TextAlign.center,
              style: const TextStyle(fontSize: 15, color: DZColors.mainColor),
            ),
            Container(
              height: kButtonHeight,
              width: double.infinity,
              margin: const EdgeInsets.only(left: 16, right: 16, top: 15),
              child: XinDongCommonButton("同意并继续", onTap: () async {
                if (Platform.isIOS) {
                  XinDongYinSiSingleton.to.changePrivacy();
                }
                Get.back(result: true);
              }),
            ),
            GestureDetector(
              onTap: () => XinDongPageSingleton.instance.exitApplication(),
              behavior: HitTestBehavior.opaque,
              child: Container(
                height: kButtonHeight,
                alignment: Alignment.center,
                child: const Text(
                  "不同意，退出应用",
                  style: TextStyle(fontSize: 15, color: DZColors.contentColor),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
